package com.zhouzi.zhaoyang.ui.activity

import android.content.Intent
import com.bumptech.glide.Glide
import com.zhouzi.zhaoyang.R
import com.zhouzi.zhaoyang.base.BaseActivity
import com.zhouzi.zhaoyang.bean.BalancePaymentBean
import com.zhouzi.zhaoyang.util.Calculator
import extension.log
import kotlinx.android.synthetic.main.pay_order_success_activity.*
import java.util.*


class PayOrderSuccessActivity : BaseActivity() {


    override fun getLayoutId(): Int {
       return R.layout.pay_order_success_activity
    }

    override fun initView() {
        val data = intent.getParcelableExtra<BalancePaymentBean>("data")
       if (data != null){
           tvRemainingSum.text = "￥"+Calculator.fen2Yuan(data.realFee!!.toLong())
           tvCompany.text = data.storeName.toString()
       }
        var money = intent.getStringExtra("webSocketMoney")
        var storeName = intent.getStringExtra("storeName")
        if (money != null && storeName != null){
            tvRemainingSum.text ="￥"+ money
            tvCompany.text = storeName
//            tvCompany.text = company
        }
        countDown()
        tvCountDown.setOnClickListener {
            var intent = Intent(mContext, MainActivity::class.java)
            startActivity(intent)
        }
       if ( data != null && data.logoUrl != null){
           Glide.with(this)
                   .load(data.logoUrl)
                   .into(iv_brand)
       }
        }



    var timer = Timer()
    private fun countDown() {
        timer.schedule(timerTask,1000,1000)

    }





    private var count = 7
    internal var timerTask: TimerTask = object : TimerTask() {
        override fun run() {
            runOnUiThread(Runnable {

                count--
                tvCountDown.setText("完成（" + count+"s）")

                if (count == 0 ){
                    timer.cancel()

                    var intent = Intent(mContext, MainActivity::class.java)
                    startActivity(intent)
                }


            })
        }
    }





}

